const initialValue = [
  {
    id: 16,
    name: 'Java开发工程师题库（1）',
    questionIds: [
      'c8c6d34b539245c1ae04bb55b4cd8ba9',
      '9ccc663034d64a3ba6af2d45f025e6cf',
      'f7fbcca9d0af49fe948465bf194471c3',
      'b9dfbb3afbec412e9a4ea7a7a5cd75c3',
      '28b33a9d112c4303be80b2fc2d52bb1b'
    ],
    creatorId: '68042014e23c4ebea7234cb9c77cee5c',
    creatorName: '小陈老师'
  },
  {
    id: 15,
    name: '开发技术基础题库（1）',
    questionIds: [
      'b9dfbb3afbec412e9a4ea7a7a5cd75c3',
      '28b33a9d112c4303be80b2fc2d52bb1b'
    ],
    creatorId: '68042014e23c4ebea7234cb9c77cee5c',
    creatorName: '小陈老师'
  },
  {
    id: 14,
    name: '开发技术基础题库（2）',
    questionIds: [
      'b9dfbb3afbec412e9a4ea7a7a5cd75c3',
      '28b33a9d112c4303be80b2fc2d52bb1b'
    ],
    creatorId: '68042014e23c4ebea7234cb9c77cee5c',
    creatorName: '小陈老师'
  },
  {
    id: 13,
    name: '开发技术基础题库（2）',
    questionIds: [
      'c8c6d34b539245c1ae04bb55b4cd8ba9',
      '9ccc663034d64a3ba6af2d45f025e6cf',
      'f7fbcca9d0af49fe948465bf194471c3',
      'b9dfbb3afbec412e9a4ea7a7a5cd75c3'
    ],
    creatorId: '68042014e23c4ebea7234cb9c77cee5c',
    creatorName: '小陈老师'
  },
  {
    id: 12,
    name: '生活基本礼仪测试题库',
    questionIds: [],
    creatorId: 'a1b661031adf4a8f969f1869d479fe74',
    creatorName: '小卫师傅'
  },
  {
    id: 11,
    name: '软件工程测试题库',
    questionIds: [],
    creatorId: '68042014e23c4ebea7234cb9c77cee5c',
    creatorName: '小陈老师'
  },
  {
    id: 10,
    name: '前端开发题库',
    questionIds: [
      'c8c6d34b539245c1ae04bb55b4cd8ba9',
      '9ccc663034d64a3ba6af2d45f025e6cf',
      'f7fbcca9d0af49fe948465bf194471c3',
      'b9dfbb3afbec412e9a4ea7a7a5cd75c3',
      '28b33a9d112c4303be80b2fc2d52bb1b'
    ],
    creatorId: '68042014e23c4ebea7234cb9c77cee5c',
    creatorName: '小陈老师'
  },
  {
    id: 9,
    name: '小米2015年实习生笔试题库',
    questionIds: [
      'c8c6d34b539245c1ae04bb55b4cd8ba9',
      '9ccc663034d64a3ba6af2d45f025e6cf',
      'f7fbcca9d0af49fe948465bf194471c3',
      'b9dfbb3afbec412e9a4ea7a7a5cd75c3'
    ],
    creatorId: '68042014e23c4ebea7234cb9c77cee5c',
    creatorName: '小陈老师'
  },
  {
    id: 8,
    name: '工商银行2014年招聘笔试题库',
    questionIds: [],
    creatorId: 'a1b661031adf4a8f969f1869d479fe74',
    creatorName: '小卫师傅'
  },
  {
    id: 7,
    name: '金山2013年暑期实习招聘笔试题库（C++）',
    questionIds: [],
    creatorId: 'a1b661031adf4a8f969f1869d479fe74',
    creatorName: '小卫师傅'
  },
  {
    id: 6,
    name: '农业银行2014年招聘笔试题库',
    questionIds: [],
    creatorId: 'a1b661031adf4a8f969f1869d479fe74',
    creatorName: '小卫师傅'
  },
  {
    id: 5,
    name: 'Android初级开发题库',
    questionIds: [],
    creatorId: '68042014e23c4ebea7234cb9c77cee5c',
    creatorName: '小陈老师'
  },
  {
    id: 4,
    name: 'Android初级开发题库',
    questionIds: [],
    creatorId: '68042014e23c4ebea7234cb9c77cee5c',
    creatorName: '小陈老师'
  },
  {
    id: 3,
    name: '小学英语（1）期末综合练习题库',
    questionIds: [],
    creatorId: 'a1b661031adf4a8f969f1869d479fe74',
    creatorName: '小卫师傅'
  },
  {
    id: 2,
    name: '单位换算专项题库',
    questionIds: [],
    creatorId: 'a1b661031adf4a8f969f1869d479fe74',
    creatorName: '小卫师傅'
  },
  {
    id: 1,
    name: '小学英语（1）期末综合练习题库',
    questionIds: [],
    creatorId: 'a1b661031adf4a8f969f1869d479fe74',
    creatorName: '小卫师傅'
  },
  {
    id: 0,
    name: '小学六年级（上）数学练习题库（统计与概率）',
    questionIds: [],
    creatorId: 'a1b661031adf4a8f969f1869d479fe74',
    creatorName: '小卫师傅'
  }
]

const questionBank = {
  state: {
    banks: initialValue,
    nextIncrementIndex: 17
  },
  mutations: {
    createBank(state, { newBank }) {
      newBank.id = state.nextIncrementIndex
      state.nextIncrementIndex += 1
      state.banks = [
        newBank, ...state.banks
      ]
    },
    deleteBank(state, { bankId }) {
      const deleteIndex = state.banks.findIndex(b => b.id === bankId)
      state.banks.splice(deleteIndex, 1)
    },
    updateBank(state, { bankId, updateBankInfo }) {
      const updateIndex = state.banks.findIndex(b => b.id === bankId)
      const notUpdatedBank = state.banks[updateIndex]
      state.banks[updateIndex] = {
        ...notUpdatedBank,
        ...updateBankInfo
      }
    }
  },
  getters: {
    queryBank: state => state.banks,
    queryByPage: state => (offset, limit) => {
      return state.banks.slice(offset, offset + limit)
    },
    total: state => state.banks.length,
    queryBankById: state => bankId => {
      return state.banks.find(b => b.id === bankId)
    }
  }
}

export default questionBank
